import { ref } from 'vue'
import { updatePostingMsgPushNodeOaPerson as updatePostingMsgPushNodeOaPersonApi } from '@/api/basic'

/**
 * 更新过账时消息推送人员（OA）通知服务
 */
export default function () {
  const updatePostingMsgPushNodeOaPersonLoading = ref(false)
  const updatePostingMsgPushNodeOaPersonForm = ref<{
    empIds: Array<string>
    pushMessageId: string
  }>({
    empIds: [],
    pushMessageId: '',
  })

  const resetUpdatePostingMsgPushNodeOaPersonForm = () => {
    updatePostingMsgPushNodeOaPersonForm.value = {
      empIds: [],
      pushMessageId: '',
    }
  }

  const updatePostingMsgPushNodeOaPerson = async () => {
    try {
      updatePostingMsgPushNodeOaPersonLoading.value = true
      const res = await updatePostingMsgPushNodeOaPersonApi(
        updatePostingMsgPushNodeOaPersonForm.value,
      )
      updatePostingMsgPushNodeOaPersonLoading.value = false
      return res.data
    } catch (error) {
      updatePostingMsgPushNodeOaPersonLoading.value = false
    }
  }

  return {
    updatePostingMsgPushNodeOaPersonForm,
    updatePostingMsgPushNodeOaPersonLoading,
    updatePostingMsgPushNodeOaPerson,
    resetUpdatePostingMsgPushNodeOaPersonForm,
  }
}
